package com.lehecai.core.api.pstation;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;
import com.lehecai.core.util.CoreStringUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * Created by He Wang on 14-8-7.
 */
public class PstationResult extends AbstractApiResultBean {

	private Long id;
	private String name;
	private String key;
	private String typeName;
	private String statusName;
	private String content;
	private String result;

	private Date createdTime;
	private Date updatedTime;
	private Date sentTime;
	private Date receivedTime;
	private Date executingTime;
	private Date finishTime;

	private String descContent;
	private String descResult;//暂时不用

	public static PstationResult convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		PstationResult pstationResult = new PstationResult();
		pstationResult.setId(getLong(object, "id"));
		pstationResult.setName(getString(object, "name"));
		pstationResult.setKey(getString(object, "key"));
		pstationResult.setTypeName(getString(object, "type"));
		pstationResult.setStatusName(getString(object, "status"));
		//content不为空，不用判断
		pstationResult.setContent(CoreStringUtils.unicodeToString(getString(object, "content")));
		//result可能为空，需要判断
		pstationResult.setResult(getString(object, "result") == null ? "" : CoreStringUtils.unicodeToString(getString(object, "result")));
		pstationResult.setCreatedTime(CoreDateUtils.parseDate(getString(object, "created_time"), CoreDateUtils.DATETIME));
		pstationResult.setUpdatedTime(CoreDateUtils.parseDate(getString(object, "updated_time"), CoreDateUtils.DATETIME));
		pstationResult.setSentTime(CoreDateUtils.parseDate(getString(object, "sent_time"), CoreDateUtils.DATETIME));
		pstationResult.setReceivedTime(CoreDateUtils.parseDate(getString(object, "received_time"), CoreDateUtils.DATETIME));
		pstationResult.setExecutingTime(CoreDateUtils.parseDate(getString(object, "executing_time"), CoreDateUtils.DATETIME));
		pstationResult.setFinishTime(CoreDateUtils.parseDate(getString(object, "finish_time"), CoreDateUtils.DATETIME));
		pstationResult.setDescContent(getString(object, "desc_content"));
		pstationResult.setDescResult(getString(object, "desc_result"));
		return pstationResult;
	}

	public static List<PstationResult> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<PstationResult> list = new ArrayList<PstationResult>();

		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public String getStatusName() {
		return statusName;
	}

	public void setStatusName(String statusName) {
		this.statusName = statusName;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public Date getUpdatedTime() {
		return updatedTime;
	}

	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}

	public Date getSentTime() {
		return sentTime;
	}

	public void setSentTime(Date sentTime) {
		this.sentTime = sentTime;
	}

	public Date getReceivedTime() {
		return receivedTime;
	}

	public void setReceivedTime(Date receivedTime) {
		this.receivedTime = receivedTime;
	}

	public String getDescContent() {
		return descContent;
	}

	public void setDescContent(String descContent) {
		this.descContent = descContent;
	}

	public String getDescResult() {
		return descResult;
	}

	public void setDescResult(String descResult) {
		this.descResult = descResult;
	}

	public Date getExecutingTime() {
		return executingTime;
	}

	public void setExecutingTime(Date executingTime) {
		this.executingTime = executingTime;
	}

	public Date getFinishTime() {
		return finishTime;
	}

	public void setFinishTime(Date finishTime) {
		this.finishTime = finishTime;
	}
}
